package com.xhh.nphm.web.controller.system;

import com.xhh.nphm.common.core.controller.BaseController;
import com.xhh.nphm.common.core.domain.AjaxResult;
import com.xhh.nphm.common.utils.DateUtils;
import com.xhh.nphm.system.domain.DeferAuto;
import com.xhh.nphm.system.service.IDeferAutoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author zz
 */
@RestController
@RequestMapping("/system/deferAuto")
public class DeferAutoController extends BaseController {
    private static final String prefix = "/system/deferAuto";

    @Autowired
    private IDeferAutoService deferAutoService;

    /**
     * 自动延期配置详情页面
     */
    @GetMapping("/config")
    public ModelAndView config(ModelMap modelMap) {
        String deptId = getSysUser().getDeptId().toString();
        DeferAuto deferAuto = deferAutoService.findByDeptId(deptId);
        //若无该单位自动延期配置记录，则只传递部门信息
        if (deferAuto == null) {
            modelMap.put("dept",getSysUser().getDept());
        }else{
            modelMap.put("deferAuto", deferAuto);
        }
        return new ModelAndView(prefix + "/config");
    }

    /**
     * 保存或修改
     * @param deferAuto 自动延期配置信息
     * @return 影响结果
     */
    @PostMapping("/saveOrUpdate")
    public AjaxResult saveOrUpdate(DeferAuto deferAuto) {
        //记录更新时间
        deferAuto.setUpdateTime(DateUtils.getNowDate());
        return toAjax(deferAutoService.saveOrUpdate(deferAuto));
    }

}
